
<template>
  <div class="accountList">
    <div class="searchBox">
      <el-form :model="searchForm" ref="searchFormRef">
        <el-row>
          <el-form-item prop="title">
            <div class="item">
              <span v-html="'动态标题'" class="nameSpan"></span>
              <el-input
                size="mini"
                v-model="searchForm.title"
                placeholder="请输入动态标题"
              ></el-input>
            </div>
          </el-form-item>
       
          <el-form-item>
            <el-button
              @click="searchClick"
              icon="el-icon-search"
              type="primary"
              size="mini"
              >查询</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetClick"
              >重置</el-button
            >
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="tableBox" ref="tableBoxRef">
      <el-table
      :height="655"
        v-loading="tableLoading"
        :header-cell-style="{
          background: '#F8F8F8',
          color: '#333',
          fontSize: '16px',
          fontWeight: '700',
        }"
        border
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column
          prop="title"
          align="center"
          label="动态标题"
           
        >
        </el-table-column>
             <el-table-column
             sortable
          prop="commentCount"
          align="center"
          label="总评论数"
           
        >
        </el-table-column>
          <el-table-column
           sortable
          prop="notAuditCommentCount"
          align="center"
          label="待审核评论数"
           
        >
        </el-table-column>
        <el-table-column
          prop="commentTime"
          align="center"
          label="最近评论时间"
           
        >
         <template slot-scope="scope" v-if='scope.row.commentTime'>{{
            scope.row.commentTime | formatDate
          }}</template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button
              icon="el-icon-edit-outline"
              size="mini"
              type="text"
              v-has="'community:comment:list'"
              @click="changeComments(scope.row)"
              >查看评论</el-button
            >
           
          </template>
        </el-table-column>
      </el-table>

        <el-card class="footer" v-if="total > 0">
         <div>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[15, 30, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
       </el-card>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      title: "",
      searchForm: {
        title: "",
      },
      tableLoading: false,
      tableHeight: 50,
      tableData: [],
      pageNum: 1,
      pageSize: 15,
      total: 0,
    };
  },

  computed: {
    ...mapGetters(["permissions"]),
  },
  created() {
    this.getCommentsList();
  },
  methods: {
    changeComments(row) {
      console.log(row.id);
      this.$router.push({
        path: "/communityManagement/changeComment",
        query: { id: row.id, title: "查看评论" },
      });
    },

    searchClick() {
      this.pageNum = 1;
      this.getCommentsList();
    },
    resetClick() {
      this.$refs.searchFormRef.resetFields();
      this.pageNum = 1;
      this.getCommentsList();
    },

    /**
     * 获取用户列表
     * @param {*}
     */
    async getCommentsList() {
      this.tableLoading = true;
      await this.$api
        .auditList({
          pageSize: this.pageSize,
          pageNum: this.pageNum,
            ...this.searchForm,
        })
        .then((res) => {
          if (res.data.code == "00000") {
            this.total = res.data.result.total;
            this.tableData = res.data.result.list;
            this.tableLoading = false;
          }
        });
    },
    /**
     * 切换页面大小
     * @param {*} val
     */
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getCommentsList();
    },

    /**
     * 页码切换
     * @param {*} val
     */
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.getCommentsList();
    },
  },
};
</script>

<style lang="less" scoped>
.accountList {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px;
  .searchBox {
    .el-row {
      display: flex;
      flex-wrap: wrap;
      .el-form-item {
        margin-bottom: 0;
      }
      .item {
        display: flex;
        align-items: center;
        margin-right: 20px;
        .nameSpan {
          padding-right: 10px;
          box-sizing: border-box;
          white-space: nowrap;
        }
        .el-input {
          width: 162px;
        }
      }
    }
  }
   .topBtn {
    margin: 10px 0;
text-align: right;
  }

  .addEditAccountDialog {
    .el-form-item {
      .el-select {
        width: 100%;
      }
    }
    .btns {
      text-align: right;
      margin-bottom: 0;
    }
  }
}
/deep/.el-button--success.is-plain {
  color: #fff;
  border-color: #409eff;
  background-color: #409eff;
}
/deep/.el-form-item {
  margin-bottom: 12px;
}
.content {
  height: 60vh;
  overflow-x: hidden;
}
/deep/.el-upload--picture-card {
  width: 400px;
  height: 270px;
}
/deep/.el-upload--picture-card i {
  margin-top: 128px;
}
</style>